 const ipcRenderer = require('electron').ipcRenderer;
 let sr=1;
 function sleep(sleepTime) {
for(var start = +new Date; +new Date - start <= sleepTime; ) { } 
}
 
let biasX = 0;
let biasY = 0;



ipcRenderer.on('qunfakaishi', function(event, arg) {
  console.log("test 2"+arg); 
  document.getElementById("title").innerHTML=arg;
});

function moveEvent(e) {
  ipcRenderer.send('suspensionWindowMove', {x: e.screenX - biasX, y: e.screenY - biasY})
}

 window.onload = function(){  
            var box = document.getElementById("dialog");
            document.getElementById("title").innerHTML="暂无任务"
			document.getElementById("dialog").onclick = () => {
				if(document.getElementById("title").innerHTML=="企微群发"){
					ipcRenderer.send('startqf');
				}
				if(document.getElementById("title").innerHTML=="企微标签"){
					ipcRenderer.send('startdbq');
				}
				if(document.getElementById("title").innerHTML=="选择文件"){
					ipcRenderer.send('qunfa');
				}
				
			}
			box.addEventListener('mousedown', function (e) {
			
			  switch (e.button) {
				case 0:
				  biasX = e.x;
				  biasY = e.y;
				  document.addEventListener('mousemove', moveEvent);
				  break;
				case 2:
				  ipcRenderer.send('createSuspensionMenu');
				break;
			  }
			});
			box.addEventListener('mouseup', function () {
			  document.getElementById("lxh").src="../img/lxh/0 ("+Math.floor(Math.random() * 77)+").gif";
			  biasX = 0;
			  biasY = 0;
			  document.removeEventListener('mousemove', moveEvent)
			});

			
        };